<?php
/**
 * Created by PhpStorm.
 * User: wangwenshan
 * Date: 2019/1/17
 * Time: 8:49
 */

namespace app\api\model;


use think\Db;

class Banner extends BaseModel
{
    protected $hidden = ['delete_time','update_time'];
    public function items(){
        return $this->hasMany('BannerItem','banner_id','id');
    }
    public static function getBannerByID($id)
    {
        // 根据banner id号，获取banner信息
        // 原生sql语句
        // $result = Db::query('select * from banner_item where banner_id=?',[$id]);
        // 查询构造器
        // $result = Db::table('banner_item')->where('banner_id','=',$id)->select();
        // 表达式、数组法、闭包
        // $result = Db::table('banner_item')
        // ->where(function ($query) use ($id){
        // $query->where('banner_id','=',$id);
        // })
        // ->select();
        $result = self::with(['items','items.img'])->find($id);
         return $result;
    }
}